"""
数据模型定义
"""
from pydantic import BaseModel, Field
from typing import Optional, List, Literal, Any
from datetime import datetime


# 认证相关模型
class LoginRequest(BaseModel):
    """登录请求"""
    username: str
    password: str


class TokenData(BaseModel):
    """令牌数据"""
    username: str


class User(BaseModel):
    """用户信息"""
    id: int
    username: str
    name: Optional[str] = None
    email: Optional[str] = None
    role: Literal["admin", "user"] = "user"
    avatar: Optional[str] = None


class LoginResponse(BaseModel):
    """登录响应"""
    token: str
    user: User
    expiresIn: int


# 通用响应模型
class ApiResponse(BaseModel):
    """通用API响应"""
    success: bool = True
    data: Optional[Any] = None
    message: Optional[str] = None


# 进程模型
class Process(BaseModel):
    """进程信息"""
    pid: int
    name: str
    cpu: float
    memory: int
    user: str
    status: str
    port: str


# 机器信息模型
class Machine(BaseModel):
    """机器信息"""
    id: int
    name: str
    ip: str
    status: Literal["online", "offline", "warning"]
    cpu: int
    memory: int
    disk: int
    os: str
    purpose: str
    owner: str
    location: Optional[str] = None
    uptime: Optional[str] = None
    lastReboot: Optional[str] = None
    processes: Optional[List[Process]] = None


# 数据库模型
class Database(BaseModel):
    """数据库状态"""
    id: int
    name: str
    host: str
    port: Optional[int] = None
    type: Optional[str] = None
    status: Optional[Literal["running", "stopped", "error", "normal", "warning"]] = "normal"
    connections: Optional[int] = None
    size: Optional[str] = None
    qps: Optional[int] = None
    uptime: Optional[str] = None


# 告警模型
class Alarm(BaseModel):
    """告警信息"""
    id: int
    time: str
    level: Literal["critical", "warning", "info"]
    source: str
    message: str
    status: Literal["pending", "resolved", "ignored", "active"]
    type: Optional[str] = None
